Ext.define('HGMIDE.controller.PackController', {
	extend : 'Ext.app.Controller',
	config : {
		refs : {
			packBtn : '#packBtn'
		},
		control : {
			packBtn : {
				tap : 'doPack'
			}
		}
	},
	doPack : function() {
		var currentEmulatorScreen = EmulatorManager.currentEmulator;
		if (currentEmulatorScreen != null) {
			var id = EmulatorManager.currentEmulator.getId();
			var idNum = id.substring(id.indexOf('r') + 1);
			var store = Ext.data.StoreManager.lookup('pluginListStore');
			store.each(function(item, index, length) {
				if (item.get("id") == idNum) {
					if(item.get("isonline") == 1){
						Ext.Msg.show({
						     message: I18N.nopack,
						     buttons: [
						    	 {text:'确定',itemId:'ok'},
						     ]
						});
						return;
					}
					Ext.Ajax.request({
						url : 'checkCerAction?appName=' + item.get('name'),
						method : 'GET',
						success : function(response, opts) {
							text = response.responseText;
							text = "YES";
							if (text === 'YES') {
								var cmdStr = cmdFlag.CMD4Pack
										+ cmdFlag.CMDFlagSeperator + '{"id":'
										+ item.get('id') + ',"name":"'
										+ item.get('name') + '","nameCN":"'
										+ item.get('nameCN') + '","dept":"'
										+ item.get('dept') + '","version":"'
										+ item.get('version') + '","frame":"'
										+ item.get('frame') 
										+ '","isonline":"'	+ item.get('isonline') 
										+ '","url":"'	+ item.get('url') 
										+ '","root":""}';
								send(cmdStr);
								Ext.Viewport.add(Util.loadingMaskPanel);
								Util.loadingMaskPanel.show();
								Ext.getCmp('waitingPanel')
										.setHtml(I18N.packing);
							} else if (text === 'NO') {
								function callback(buttonId, value, opt) {
									if (buttonId == 'yes') {
										var settingBtn = Ext
												.getCmp('settingBtn');
										settingBtn.fireEvent('tap', settingBtn);
									}
								};
								Ext.Msg.confirm(I18N.promptTitle,
										I18N.please_cer, callback);
							}
						}
					});
				}
			});
		}
	}
});
